﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../Brushes.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <Converters:ToUpperConverter x:Key="ToUpperConverter" />

  <!-- x:Key="MetroGroupBox" -->
  <Style TargetType="{x:Type GroupBox}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Margin" Value="5" />
    <Setter Property="Padding" Value="5" />
    <Setter Property="Foreground" Value="{DynamicResource GroupBoxForeground}"/>
    <Setter Property="Background" Value="{DynamicResource GroupBoxBackground}"/>
    <Setter Property="BorderBrush" Value="{DynamicResource GroupBoxBorderBrush}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type GroupBox}">
          <Grid x:Name="GroupBoxRoot">
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Border Grid.Row="0"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="1">
              <ContentPresenter Margin="{TemplateBinding Padding}"
                                              ContentSource="Header"
                                              RecognizesAccessKey="True">
                <ContentPresenter.Resources>
                  <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=Background, Converter={x:Static Converters:BackgroundToForegroundConverter.Instance}}" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                  </Style>
                </ContentPresenter.Resources>
                <ContentPresenter.Content>
                  <Binding Converter="{StaticResource ToUpperConverter}"
                                             Path="Header"
                                             RelativeSource="{RelativeSource TemplatedParent}" />
                </ContentPresenter.Content>
              </ContentPresenter>
            </Border>
            <Border Grid.Row="1"
                                Background="Transparent"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="1,0,1,1">
              <ContentPresenter Margin="{TemplateBinding Padding}"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              Cursor="{TemplateBinding Cursor}" />
            </Border>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>
